package com.stud.rmi;

import com.stud.exception.ValidationException;
import com.stud.repository.ClientRepository;
import com.stud.validation.Validator;

import java.math.BigDecimal;

public class ServiceImpl implements Service {

    private final ClientRepository clientRepository;
    private final Validator validator;

    public ServiceImpl(ClientRepository clientRepository, Validator validator) {
        this.clientRepository = clientRepository;
        this.validator = validator;
    }

    @Override
    public Account getAccount(Client client) {
        return new Account(1, new BigDecimal(100));
    }

    @Override
    public void saveClient(Client client) {
        clientRepository.save(client);
    }

    @Override
    public void deleteClient(Client client) throws ValidationException {
        validator.validate(client);
        clientRepository.delete(client);
    }
}
